package cn.itsource.smartcampus.controller;

import cn.itsource.smartcampus.domain.LoginUser;
import cn.itsource.smartcampus.exception.GlobalException;
import cn.itsource.smartcampus.service.LoginuserService;
import cn.itsource.smartcampus.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginuserController {
    @Autowired
    private LoginuserService service;
   @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginUser user)  {
        try {
            String token = service.login(user);
            System.out.println(token);
            return AjaxResult.me().setSuccess(true).setResultObj(token);
        } catch (GlobalException ge) {
            return AjaxResult.me().setSuccess(false).setMessage(ge.getMessage());
        } catch (Exception e){
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage("系统异常，请联系管理员");
        }


    }
}
